<template>
	<view class="content" v-if="pageshow">
		<view class="padding">
			<view class="">
				<!-- 订单状态 -->
				<!-- state  1=待支付,2=待发货,3=待收货,4=待评论,5=售后订单(已弃用),6=已完成,7=已取消 -->
				<!-- refund_status -> 0=未退款,1=退款中,2=待退货,3=退款完成,4=退款关闭,5=退款被拒 -->
				<!-- 0 4 5一样 -->
				<view class="bigtext" v-if="orderDetail.state==1 && orderDetail.refund_status==0">等待买家付款</view>
				<view class="bigtext" v-if="orderDetail.state==2 && orderDetail.order_type==1 && orderDetail.refund_status==0">等待商家处理</view>
				<view class="bigtext" v-if="orderDetail.state==3 && orderDetail.order_type==1 && orderDetail.refund_status==0">等待到店取货</view>
				<view class="bigtext" v-if="orderDetail.state==2 && orderDetail.order_type==2 && orderDetail.refund_status==0">等待商家发货</view>
				<view class="bigtext" v-if="orderDetail.state==3 && orderDetail.order_type==2 && orderDetail.refund_status==0">等待买家收货</view>
				<!-- <view class="bigtext" v-if="orderDetail.state==4 && orderDetail.refund_status==0">等待买家评论</view> -->
				<view class="bigtext" v-if="orderDetail.state==4">等待买家评论</view>
				<view class="bigtext" v-if="orderDetail.state==6 && orderDetail.refund_status==0">已完成</view>
				
				<view class="bigtext" v-if="orderDetail.state==7 && orderDetail.refund_status==0">已取消</view>
				<view class="bigtext" v-if="orderDetail.refund_status==1">退款中</view>
				<view class="bigtext" v-if="orderDetail.refund_status==2">退货售后中</view>
				<view class="bigtext" v-if="orderDetail.refund_status==3">退款完成</view>
				<view class="bigtext" v-if="orderDetail.refund_status==4">退款关闭</view>
				<!-- <view class="bigtext" v-if="orderDetail.refund_status==5">等待买家收货</view> -->
			</view>
			<!--订单时间状态  -->
			<view class="margin_top1">
				<view class="strongtext" v-if="orderDetail.state==2 && orderDetail.order_type==1">商家正在处理中~</view>
				<view class="strongtext " v-if="orderDetail.state==2 && orderDetail.order_type==2">请您耐心等待商家发货~</view>
				<view class="strongtext " v-if="orderDetail.state==6">感谢您的支持，欢迎下次购买！</view>
				<view class="strongtext " v-if="orderDetail.state==3 && orderDetail.order_type==1">请您到门店取货</view>
				<view class="strongtext " v-if="orderDetail.state==7">您已取消此订单</view>
			</view>
			<!-- 地址 -->
			<view class="padding ffffff border_2 margin_top">
				<view class="flexbetween">
					<!-- 1=到店自提,2=物流配送 -->
					<view class="" v-if="orderDetail.order_type==1">
						<view class="flexleft">
							<view class=" word_baiba black margin_right3">{{orderDetail.shopconfig.returnName}}</view>
							<view class=" word_baiba black">{{orderDetail.shopconfig.returnPhoneNum}}</view>
						</view>
						<view class="huisetext margin_top2">{{orderDetail.shopconfig.returnAddr}}</view>
					</view>
					<!-- 1=到店自提,2=物流配送 -->
					<view class="" v-if="orderDetail.order_type==2">
						<view class="flexleft">
							<view class=" word_baiba black margin_right3">{{orderDetail.address.name}}</view>
							<view class=" word_baiba black">{{orderDetail.address.mobile}}</view>
						</view>
						<view class="huisetext margin_top2">{{orderDetail.address.address}}</view>
					</view>
				</view>
			</view>
			<!-- 商品 -->
			<view class="ffffff padding border_2 margin_top">
				<!-- 退货商品 -->
				<!--  <view class="word_hh hei padding_bottom">退货商品</view>  -->
				<view class="flexleft">
					<view class="margin_right2 order">订单商品</view>
				</view>
				<view class=" xiahuax margin_top" v-for="item in orderDetail.goods" :key="item.id" @click="goGoodsInfo(item.goods_id)">
					<view class="flexbetween">
						<view class="shilitu">
							<image :src="item.image_text" mode=""></image>
						</view>
						<view class="" style="width: 74%;">
							<view class="ershib yhxiank">{{item.title}}</view>
							<view class="margin_top1 white">{{item.difference}}</view>
							<view class="flexbetween margin_top1">
								<view class="qianshu">¥{{item.price}}</view>
								<view class="shuliang">X{{item.number}}</view>
							</view>
						</view>
					</view>
					<view class="flexright margin_top">
						<!-- 立即评价 -->
						<view class="huisebtn margin_right2" v-if="item.refund_status==0 && orderDetail.state==4 && item.comment_status==1" @click.native.stop="estimate(item.id)">立即评价</view>
					</view>
				</view>
			</view>
			<!-- 核销二维码 -->
			<view class="code border_2" v-if="orderDetail.order_type==1 && orderDetail.state==3">
				<view class="flexcenter flexcolumn">
					<!-- <image src="../static/logo.png" mode="" class="erwie"></image> -->
					<uqrcode ref="uqrcode" canvas-id="qrcode" @click="ewmfn" v-bind:value="qrcodeurl" size="120" :options="{ margin: 10 }"></uqrcode>
					<view class="margin_top1 hexiao">核销码</view>
				</view>
			</view>
			<!-- 商品详情 -->
			<view class="paddingbom">
				<view class="ffffff padding border_2 margin_top">
					<view class="flexbetween">
						<view class="tuihuo">商品金额</view>
						<view class="huisetext" style="color:rgba(212, 139, 57, 1);">¥{{orderDetail.total_price}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">运费</view>
						<view class="huisetext">¥{{orderDetail.freight_price}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">总价</view>
						<view class="huisetext">¥{{orderDetail.pay_price}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">订单编号</view>
						<view class="huisetext">{{orderDetail.order_no}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">下单时间</view>
						<view class="huisetext">{{orderDetail.paymenttime_text}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="tuihuo">支付方式</view>
						<view class="huisetext">{{orderDetail.pay_type_text}}</view>
					</view>
					<view class="flexbetween margin_top" style="align-items: flex-start;">
						<view class="tuihuo" style="width: 800rpx;">备注</view>
						<view class="huisetext">{{orderDetail.remarks}}</view>
					</view>

				</view>
			</view>
			<!-- 固定底部 -->
			<view class="gudingdb ffffff">
				<view class="flexright">
					<!--退货/售后-->
					<view class="huisebtn margin_right2" @click="tzthsh" v-if="orderDetail.refund_status==0&&orderDetail.state==3&&orderDetail.order_type!=1">退货/售后</view>
					<!-- 查看物流 -->	
					<view class="huisebtn margin_right2" @click="ckwj" v-if="orderDetail.refund_status!=2&&orderDetail.refund_status!=3&&orderDetail.state==3&&orderDetail.order_type==2">查看物流</view>
					<!-- 确认收货 -->
					<view class="huangsebtn margin_right3" @click="suresh" v-if="(orderDetail.refund_status==0||orderDetail.refund_status==4||orderDetail.refund_status==5)&&orderDetail.state==3&&orderDetail.order_type==2">确认收货</view>
					<!-- 取消订单-->
					<view class="huisebtn margin_right2" @click="cancelorder" v-if="orderDetail.state==1||orderDetail.state==2">取消订单</view>
					<!-- 立即支付 -->
					<view class="huangsebtn margin_right3" @click="atoncePay" v-if="orderDetail.state==1">立即支付</view>
					<!-- 删除订单 -->
					<view class="huisebtn margin_right2" @click="deletorder" v-if="(orderDetail.refund_status==3||orderDetail.state==6||orderDetail.state==7)">删除订单</view>
					
				</view>
			</view>
		</view>
		<!-- 物流单号弹出框 -->
		<u-popup :show="show" mode="center" @close="close" :round="15">
			<view class="text dan">
				<text class="wuliu">物流单号</text>
				<view class="zhongtong">
					<view class="">{{orderDetail.express_name}}</view>
					<view class="text margin_top1">{{orderDetail.express_no}}</view>
				</view>
				<view class="fuzhi">
					<view class="copy" @click="copy">点击复制</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				orderID: '', // 订单 id
				orderDetail: {}, // 订单详情内容
				pageshow: false,
				qrcodeurl: '',
			}
		},
		onLoad(options) {
			let _this = this
			_this.orderID = options.id
			this.getdata()
		},
		onShow() {
			let _this = this
			_this.getOrderInfo()
		},
		methods: {
			// 二维码点击预览图片
			ewmfn() {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {
						console.log(res);
						var i = [res.tempFilePath]; //获取当前页面的轮播图数据
						//uniapp预览轮播图
						uni.previewImage({
							current: 0, //预览图片的下标
							urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
						})
					}
				});
			},
			// 查看物流
			ckwj(){
				this.show=true
			},
			// 点击复制
			copy() {
				let value = "物流名称："+this.orderDetail.express_name+" 单号："+this.orderDetail.express_no
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => {
						//复制成功的回调函数
						httpRequest.toast("复制成功")
						this.show = false
					}
				});
			},
			// 获取订单详情
			getOrderInfo() {
				let _this = this
				httpRequest.request('api/order/getOrderInfo', 'GET', {
					id: _this.orderID
				}).then(res => {
					if (res.code == 1) {
						_this.orderDetail = res.data
						this.pageshow = true
					}else if(res.code==0){
						httpRequest.toast(res.msg);
						setTimeout(()=>{
							uni.navigateBack(1)
						},500)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			// // 获取链接
			getdata() {
				let _this = this;
				httpRequest.request('api/index/getConfigInfo', 'GET', {}).then(res => {
					if (res.code == 1) {
						console.log(res.data.order_hx_url);
						_this.qrcodeurl=res.data.order_hx_url+'?tour_order_id='+this.orderID
					}
				})
			},
			goGoodsInfo(id){
				uni.navigateTo({
					url: "/pages_index/shangpinxq?id=" + id
				})
			},
			// 跳转 申请退款
			tzthsh(){
				let _this=this
				uni.navigateTo({
					url: '/pages_my/shenqingtk?price='+ _this.orderDetail.total_price +'&id=' + _this.orderDetail.id
				})
			},
			// 取消订单
			cancelorder() {
				httpRequest.modal('提示', '确定取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('api/order/cancelOrder', 'GET', {
							order_id: this.orderID,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								uni.navigateBack(1)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			// 确认收货
			suresh() {
				httpRequest.modal('提示', '请再次确认', true, (res) => {
					if (res) {
						httpRequest.request('api/order/confirmOrder', 'POST', {
							id: this.orderID,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								uni.navigateBack(1)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			atoncePay(){
				let obj = {
					id:this.orderDetail.order_pay_no,// 支付订单号
					pay_price:this.orderDetail.pay_price,// 支付金额
				}
				uni.navigateTo({
					url:'/pages_index/zhifu?msg=' + encodeURIComponent(JSON.stringify(obj))
				})
			},
			// 删除订单
			deletorder() {
				httpRequest.modal('提示', '确定删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('api/order/delOrder', 'POST', {
							id: this.orderID,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								uni.navigateBack(1)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			// 跳转 立即评价
			estimate(id) {
				uni.navigateTo({
					url: "/pages_my/lijipj?id="+id
				})
			},
			close() {
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.dan {
		width: 80vw;
		padding: 64rpx 40rpx 0rpx 40rpx;
	}
	.tuihuo {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.money_tui {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #D48B39;
	}

	.order {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.hexiao {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
	}

	.white {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.erwie {
		width: 169rpx;
		height: 169rpx;
	}

	.code {
		padding: 30rpx 30rpx;
		margin-top: 30rpx;
		background-color: #fff;
	}

	/deep/.u-safe-area-inset-bottom {
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
	}

	.fuzhi {
		padding: 0rpx 100rpx;
	}

	.copy {
		padding: 20rpx 40rpx;
		border-radius: 51rpx;
		background-color: rgba(212, 139, 57, 1);
		margin-top: 109rpx;
		color: #fff;
	}

	.dan {
		padding: 64rpx 40rpx 64rpx 40rpx;
	}

	.zhongtong {
		margin-top: 87rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		padding: 34rpx 82rpx;
		border: 1rpx solid rgba(223, 223, 223, 1);
		border-radius: 10rpx;
	}

	.wuliu {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.strongtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.bigtext {
		font-size: 34rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.xzqianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(212, 139, 57, 1);
	}

	.huangsebtn {
		border: 2rpx solid rgba(212, 139, 57, 1);
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(212, 139, 57, 1);
	}

	.huisebtn {
		border: 2rpx solid #666666;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(212, 139, 57, 1);
	}

	.huisetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.yhxiank {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.paddingbom {
		padding-bottom: 200rpx;
	}
</style>